package com.yunji.base.business;


import com.yunji.base.domain.MalfunctionDO;
import com.yunji.base.service.FeedbackService;
import com.yunji.base.service.MalfunctionService;
import com.yunji.common.model.dto.MalfunctionDTO;
import com.yunji.common.model.params.FeedbackParam;
import com.yunji.common.model.params.MalfunctionParam;
import com.yunji.common.model.vo.FeedbackExportVO;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Project: yunji-coffee
 * @Package: com.yunji.message.business
 * @Title: MalfunctionBusiness
 * <p>
 * History:
 * Date                     Version     Author          Summary
 * ============================================================
 * 2024-10-30 14:29:17      V1.0        HuaAo       故障类型
 */
@Component
public class MalfunctionBusiness {

    @Resource
    MalfunctionService malfunctionService;

    @Resource
    FeedbackService feedbackService;

    public List<MalfunctionDO> list(MalfunctionParam param) {
        return malfunctionService.search(param);
    }

    public Long create(MalfunctionDTO dto) {
        return malfunctionService.create(dto);
    }

    public boolean edit(MalfunctionDTO dto) {
        return malfunctionService.edit(dto);
    }

    public boolean delete(List<Long> ids) {
        for (Long id : ids) {
            FeedbackParam param = new FeedbackParam();
            param.setMalfunctionId(id);
            List<FeedbackExportVO> feedbackList = feedbackService.search(param);
            boolean status = false;
            if (feedbackList.isEmpty()) {
                status = true;
            }
            Assert.isTrue(status, "故障类型被使用,不能操作删除");
        }

        return malfunctionService.delete(ids);
    }
}